package com.ls.pattern.behavior.memento;

public class Main {
    public static void main(String[] args) {
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();
        originator.setState("状态#1");
        caretaker.add(originator.saveStateMemento());
        originator.setState("状态#2");
        caretaker.add(originator.saveStateMemento());
        originator.setState("状态#3");
        caretaker.add(originator.saveStateMemento());


        System.out.println(originator.getState());
        //恢复到状态1
        originator.getStateFromMemento(caretaker.get(0));
        System.out.println(originator.getState());
    }
}
